package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.PurchaseOrder;
import com.example.demo.mapper.PurchaseOrderMapper;
import com.example.demo.service.IPurchaseOrderService;
import com.example.demo.strategy.BizMethodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cici
 */
@Service
public class PurchaseOrderServiceImpl extends BaseOrderService<PurchaseOrderMapper, PurchaseOrder> implements IPurchaseOrderService {

    @Autowired
    private BizMethodService methodService;

    @Override
    public PurchaseOrder create(PurchaseOrder purchaseOrder) {
        commonLogic();
        methodService.doBizMethod(1);
        purchaseOrder.setTotalMoney(calculateTotalMoney(purchaseOrder));
        baseMapper.insert(purchaseOrder);
        return baseMapper.selectById(purchaseOrder.getId());
    }

    @Override
    public PurchaseOrder detail(Integer id) {
        return baseMapper.selectById(id);
    }

    @Override
    public IPage<PurchaseOrder> selectPage(Page<PurchaseOrder> page, PurchaseOrder purchaseOrder) {
        return baseMapper.selectPageByCondition(page,purchaseOrder);
    }
}
